﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BookStore
{
    public class data
    {
        public string Command;
        public string Content;
        //构造函数
        public data()
        {

        }

        //overload
        //构造函数
        public data(string command, string content)
        {
            Command = command;
            Content = content;
        }
        //overload
        //构造函数
        /// <summary>
        /// 序列化的数据大概是以  "login:456456,12349978"这样的形式
        /// </summary>
        /// <param name="entity"></param>
        public data(string entity)
        {
            int Index = entity.IndexOf(":", StringComparison.Ordinal);
            Command = entity.Substring(0, Index);
            Content = entity.Substring(Command.Length + 1);
        }

        //序列化 方便网上传输
        public string Serialize()
        {
            return string.Format("{0}:{1}", Command, Content);
        }

        //隐式转换

        public static implicit operator string(data entity)
        {
            return entity.Serialize();
        }

        public string GetCommand()
        {
            return Command;
        }

        public void SetCommand(string command)
        {
            Command = command;
        }

        public string GetContent()
        {
            return Content;
        }

        public void SetContent(string content)
        {
            Content = content;
        }
    }
}
